Sync Youtube Video Urls with Google Sheets

工作流概述

这是一个包含8个节点的中等工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "rJNvM4vU6SLUeC1d",
  "meta": {
    "instanceId": "10f6e8a86649316fe7041c503c24e6d77b68a961a9f4f1f76d0100c435446092",
    "templateCredsSetupCompleted": true
  },
  "name": "Sync Youtube Video Urls with Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "f1cd1374-2214-41c1-af32-9e31e72aab88",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1720,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "items"
      },
      "typeVersion": 1
    },
    {
      "id": "e59d5ac8-5386-4fa4-a18c-39cd84779eae",
      "name": "Manual Trigger (When Clicking 'Test workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1100,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "46897f6d-5e64-4a85-92b5-d8e596d02702",
      "name": "Get Youtube Channel Ids from Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1300,
        0
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1592454760,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4/edit#gid=1592454760",
          "cachedResultName": "Sheet3"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4/edit?usp=drivesdk",
          "cachedResultName": "Youtube Videos Comments"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "jPoTdPxgVL0vr9SQ",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "adb73854-a110-4c1e-9228-221b844a15f5",
      "name": "Get Youtube Video Urls form specific channel",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1540,
        0
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/search",
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "pageToken",
                    "value": "={{ $response.body.nextPageToken }}"
                  }
                ]
              },
              "completeExpression": "={{ !$response.body.nextPageToken}}",
              "paginationCompleteWhen": "other"
            }
          }
        },
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "channelId",
              "value": "={{ $json.channelId }}"
            },
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "order",
              "value": "date"
            },
            {
              "name": "maxResults",
              "value": "50"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "id": "2lgO4p3deoSAoU9d",
          "name": "Query Auth account 3"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d5926bd7-f1d6-4441-87de-454d16aa6928",
      "name": "Format fields as required to save in google sheet",
      "type": "n8n-nodes-base.set",
      "position": [
        1900,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "21a7a279-8a86-494c-a32f-ebcf956e2f69",
              "name": "Title",
              "type": "string",
              "value": "={{ $json.snippet.title }}"
            },
            {
              "id": "0f7084f4-9180-4eee-ab59-8e0ce75b163f",
              "name": "video_urls",
              "type": "string",
              "value": "=https://www.youtube.com/watch?v={{ $json.id.videoId }}"
            },
            {
              "id": "40b96174-109e-4ddf-b1c2-c3f0b93a2769",
              "name": "published_at",
              "type": "string",
              "value": "={{ $json.snippet.publishedAt }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e23503cd-40ae-488f-9918-83b1e3dc7b28",
      "name": "Insert & Update Youtube Urls in Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2100,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "Title": "={{ $json.Title }}",
            "video_urls": "={{ $json.video_urls }}",
            "published_at": "={{ $json.published_at }}"
          },
          "schema": [
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "video_urls",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "video_urls",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_fetched_time",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "last_fetched_time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "next_fetch_time",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "next_fetch_time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "published_at",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "published_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "video_urls"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 760258523,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4/edit#gid=760258523",
          "cachedResultName": "Sheet2"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xoCVr_mlwn4jFcnJENtrU-_K5nkIytZ8qBXzxMq55n4/edit?usp=drivesdk",
          "cachedResultName": "Youtube Videos Comments"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "jPoTdPxgVL0vr9SQ",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "428bf48c-1721-4215-9ad4-f5b85f12d6dc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        -100
      ],
      "parameters": {
        "width": 1320,
        "height": 320,
        "content": "## Sync Youtube Video Urls with Google Sheets
"
      },
      "typeVersion": 1
    },
    {
      "id": "3aaf62a9-e97e-48dd-8716-c5440759a03e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        -100
      ],
      "parameters": {
        "color": 5,
        "width": 280,
        "height": 220,
        "content": "## I'm a note 
✅ Reads Channel IDs from `Sheet3`  
📹 Fetches video URLs using YouTube API  
📄 Writes video URLs to `Sheet2`  

🔁 Output used in:  
👉 [Part 2 – YouTube Comment Sentiment Analyzer](https://n8n.io/workflows/3855-youtube-comment-sentiment-analyzer-with-google-sheets-and-openai/)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f874513c-62c9-430d-8c33-c6d48bacb74d",
  "connections": {
    "Split Out": {
      "main": [
        [
          {
            "node": "Format fields as required to save in google sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Youtube Channel Ids from Google Sheet": {
      "main": [
        [
          {
            "node": "Get Youtube Video Urls form specific channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Youtube Video Urls form specific channel": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger (When Clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "Get Youtube Channel Ids from Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format fields as required to save in google sheet": {
      "main": [
        [
          {
            "node": "Insert & Update Youtube Urls in Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Splitout
  • Manualtrigger
  • Googlesheets
  • Httprequest
  • Set

复杂度评估

配置难度:
★★★☆☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作